package com.example.lovedogs.util;


import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.view.View.OnClickListener;

public class SpanUtil {
	/**
	 * 字体前景色
	 * 
	 * @param key 需要变颜色的词汇
	 * @param symptom String字符串
	 * @param color 字体颜色
	 * @return
	 */
	public static SpannableStringBuilder setColor(String key, String symptom,
			int color) {
		SpannableStringBuilder sp = new SpannableStringBuilder(symptom);
		int start=symptom.indexOf(key);
		int end=start+key.length();
		sp.setSpan(new ForegroundColorSpan(color),start,end,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		return sp;
	}

	public static void setColors(String key, String cure,
			SpannableStringBuilder sp_cure, int color) {
		int start=cure.indexOf(key);
		int end=start+key.length();
		sp_cure.setSpan(new ForegroundColorSpan(color),start,end,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
	}
	public static void setColors(String key, String cure,
			SpannableStringBuilder sp_cure, int color,final View.OnClickListener l) {
		int start=cure.indexOf(key);
		int end=start+key.length();
		sp_cure.setSpan(new ForegroundColorSpan(color),start,end,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		sp_cure.setSpan(l, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);		
	}

}
